<?php
/**
 * Created by PhpStorm.
 * User: yvdedu.com
 * Date: 2019/6/10
 * Time: 10:02
 */

namespace app\api\model;



class SubjectCourse extends BaseModel {

    protected $pk = 'c_id';

    protected function getContentImgAttr($value){
        $url = '';
        if (!empty($value)){
            $url = config('setting.remote_img_url').$value;
        }
        return $url;
    }

    protected function getContentGifAttr($value){
        $url = '';
        if (!empty($value)){
            $url = config('setting.remote_img_url').$value;
        }
        return $url;
    }
    protected function getAskImgAttr($value){
        $url = '';
        if (!empty($value)){
            $url = config('setting.remote_img_url').$value;
        }
        return $url;
    }
    protected function getAudioAttr($value){
        $url = '';
        if (!empty($value)){
            $url = config('setting.remote_img_url').$value;
        }
        return $url;
    }
    protected function getVideoAttr($value){
        $url = '';
        if (!empty($value)){
            $url = config('setting.remote_img_url').$value;
        }
        return $url;
    }

    public function SubjectCourseLog(){
        return $this->belongsTo('SubjectCourseLog','c_id','course_id')->bind('user_id,car_status,status,result');
    }

    /**
     * 根据分类获判断题考试题目
     * @param $data
     * @param int $culture
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getJudgeExamSubject($data,$culture = 0){
        return self::where('content_type','in',$data)
            ->where('culture','=',$culture)
            ->where("item3 = ''")
            ->field('c_id,content,content_img,item1,content_gif,item2,item3,item4,item_true,key_words,key_true,key_false,culture')
            ->select();
    }


    /**
     * 根据分类获选择题考试题目
     * @param $data
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getChooseExamSubject($data,$culture = 0){
        return self::where('content_type','in',$data)
            ->where('culture','=',$culture)
            ->where("item3 != ''")
            ->field('c_id,content,content_img,item1,content_gif,item2,item3,item4,item_true,key_words,key_true,key_false,culture')
            ->select();
    }

    /**
     * 根据id获取练习题目
     * @param $ids
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getSubjectByIds($ids){
        return self::where('c_id','in',$ids)
            ->hidden(['content_type','free','false_num'])->select();
    }

    /**
     * 获取顺序练习的所有练习题
     * @param $types
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getPracticeSubject($types){
        return self::where('content_type','in',$types)
            ->hidden(['content_type','free','false_num'])
            ->select();
    }

    /**
     * 获取分类练习题
     * @param $type
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getPracticeSubjectByCategory($type){
        return self::where('content_type','=',$type)
            ->hidden(['content_type','free','false_num'])
            ->select();
    }


    /*** 随机练习
     * @param $course
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function SubjectRandom($course){
        return self::where('course',$course)
            ->field('c_id,culture,course,content_type,content,content_img,item1,item2,item3,item4,item_true,ask_img,audio,video')
            ->select();
    }

}